'use strict'

// 导入模块
const express = require('express')
const path = require('path')
const session = require('express-session')
const bodyParser = require('body-parser')
const os = require('os')

// 创建服务器
const knowErrServer = express()

// 集成静态资源
knowErrServer.use(express.static(path.join(__dirname, 'assets')))

knowErrServer.use(express.static(path.join(__dirname, '../node_modules/')))

knowErrServer.use(bodyParser.urlencoded({ extended: false }))
// 统一处理返回
knowErrServer.all('*/',(req,res,next) => {
    next();
})

// 使用路由进行模块处理
const knowErrRouter = require(path.join(__dirname, 'routers/knowErrMessage.js'))
knowErrServer.use('/main', knowErrRouter);
// 创建ip
const networkInterfaces = os.networkInterfaces();
let stepIp =
    networkInterfaces['WIFI'] ||
    networkInterfaces['以太网'] ||
    networkInterfaces['本地连接']
const IP = stepIp[1].address
// 开启服务
knowErrServer.listen(3000, IP, err => {
    if (err) {
        console.log(err);
    }
    console.log('start OK!!!');
})
